package com.commerce.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.commerce.common.entity.ProductImage;
import com.commerce.product.mapper.ProductImageMapper;
import com.commerce.product.service.ProductImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ProductImageServiceImpl extends ServiceImpl<ProductImageMapper, ProductImage> implements ProductImageService {

    @Autowired
    private ProductImageMapper productImageMapper;

    @Override
    public List<ProductImage> getProductImagesByType(Long productId, Integer type) {
        return productImageMapper.findByProductIdAndType(productId, type);
    }

    @Override
    public List<ProductImage> getAllProductImages(Long productId) {
        return productImageMapper.findByProductId(productId);
    }

    @Override
    public boolean saveProductImage(ProductImage productImage) {
        return save(productImage);
    }

    @Override
    @Transactional
    public boolean saveProductImages(List<ProductImage> productImages) {
        return saveBatch(productImages);
    }

    @Override
    public boolean deleteProductImage(Long id) {
        return removeById(id);
    }

    @Override
    @Transactional
    public boolean deleteProductImages(Long productId) {
        LambdaQueryWrapper<ProductImage> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProductImage::getProductId, productId);
        return remove(wrapper);
    }
} 